package br.com.universidade.servlets.materia;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.universidade.bean.Aluno;
import br.com.universidade.bean.Materia;
import br.com.universidade.dao.AlunoDao;
import br.com.universidade.dao.MateriaDao;

@WebServlet("/PAGES/materia/listarMateria")
public class ListarMateriaServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		try {
			MateriaDao dao = new MateriaDao();
			List<Materia> lista = dao.findAll(Materia.class);
			request.setAttribute("listaMateria", lista);
			request.getRequestDispatcher("/PAGES/materia/listarMateria.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("Erro ao listar as materias");
		}
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
